package com.gxa.service.impl;

import com.gxa.common.PaginationResult;
import com.gxa.mapper.GroupMapper;
import com.gxa.pojo.Groups;
import com.gxa.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: tx
 * Date: 2020/11/02 17:10
 * Description:
 * Version: V1.0
 */
@Service
public class GroupServiceImpl implements GroupService{
    @Autowired(required = false)
    private GroupMapper groupMapper;

    @Override
    public int addEmployeeGroup(Groups groups) {
        return groupMapper.addEmployeeGroup(groups);
    }

    @Override
    public int delEmployeeGroup(Groups groups) {
        return groupMapper.delEmployeeGroup(groups);
    }

    @Override
    public int updateEmployeeGroup(Groups groups) {
        return groupMapper.updateEmployeeGroup(groups);
    }

    @Override
    public PaginationResult queryEmployeeGroup(int currentPage, int pageSize) {
        PaginationResult paginationResult = new PaginationResult();
        //当前页码数
        paginationResult.setCurrentPage(currentPage);
        //每页显示条数
        paginationResult.setPageSize(pageSize);
        //总条数
        int totalSize = getGroupSizeConis();
        //总页数
        int totalPage = totalSize / pageSize;
        if (totalSize % pageSize != 0) {
            totalPage += 1;
        }
        paginationResult.setTotalPage(totalPage);
        paginationResult.setTotalSize(totalSize);
        int param1 = (currentPage - 1) * pageSize;
        int param2 = pageSize;
        List<Groups> groupsList = groupMapper.queryEmployeeGroup(param1, param2);
        paginationResult.setData(groupsList);
        return paginationResult;
    }

    private int getGroupSizeConis() {
        return groupMapper.getGroupSizeConis();
    }
}
